from flask import Blueprint, jsonify, request

from application.services.system.auth import AuthService
from application.utils.res import json_fail, json_success

auth_bp = Blueprint("auth", __name__, url_prefix="/auth")


@auth_bp.post("/login")
def login():
    """用户登录接口"""
    try:
        # 获取请求数据
        data = request.get_json()
        username = data.get('username')
        password = data.get('password')
        
        # 验证输入
        if not username or not password:
            return jsonify({
                "code": 400,
                "msg": "用户名和密码不能为空"
            }), 400
        
        # # 调用服务层进行认证
        result = AuthService.login(username, password)
        
        return json_success(result)
    except Exception as e:
        return json_fail(f"查询失败: {str(e)}"), 500













    # print("213123  login")
    # response_data = {
    #     "code": 200,
    #     "msg": "操作成功",
    #     "data": {
    #         "scope": None,
    #         "openid": None,
    #         "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOiJzeXNfdXNlcjoxIiwicm5TdHIiOiJoNWVJRGFjcmZLSjVLNDhBYklpa0pUZmdQMGhtNVJMViIsImNsaWVudGlkIjoiZTVjZDdlNDg5MWJmOTVkMWQxOTIwNmNlMjRhN2IzMmUiLCJ0ZW5hbnRJZCI6IjAwMDAwMCIsInVzZXJJZCI6MSwidXNlck5hbWUiOiJhZG1pbiIsImRlcHRJZCI6MTAzLCJkZXB0TmFtZSI6IueglOWPkemDqOmXqCIsImRlcHRDYXRlZ29yeSI6IiJ9.QXFlbvblQzgjgFfosBkYXhI98nnI3lalbjCA_m38-ao",
    #         "refresh_token": None,
    #         "expire_in": 604800,
    #         "refresh_expire_in": None,
    #         "client_id": "e5cd7e4891bf95d1d19206ce24a7b32e",
    #     },
    # }
    # return jsonify(response_data)


